React = require('react')
{InteractionManager,View} = require('react-native')
Dimensions = require('Dimensions')
{width,height} = Dimensions.get('window')

# 转场动画完成后调用组件的render,注意：这是通过继承原组件实现的，
# 因为需要调用原组件的renderHeader方法
renderAfterTransfer = (WrappedComponent)->
  class newComponent extends WrappedComponent
    constructor:->
      super()
      this.state = {ready:false}
    componentDidMount:->
      that = @
      super() if WrappedComponent::componentDidMount

      InteractionManager.runAfterInteractions ->
        requestAnimationFrame ->
          that.setState({ready:true})
          # if WrappedComponent::componentDidMount
          #   newComponent.__super__.componentDidMount.call(that)



    render:->
      # <WrappedComponent {...this.props}/>
      debugger
      if this.state.ready
        super()
      else
        <View style={{height:height,width:width,backgroundColor:'#ffffff'}}>
          {@renderHeader?()}
        </View>

module.exports = renderAfterTransfer
